// The purpose of this class is to accommodate methods which are common to
// classes that involve parsing json results. 

package
{
	public class Result
	{
		
		private function formRegExp(fieldName:String):String{
			var returnString:String = "\"" + fieldName + "\": \"[^\"]*\"";
			return returnString;
		}
		
		// Helper method to find a field in a JSON document and
		// return the field's data, eg find "name" might return "Mark Twain"
		// field: the field name, eg "name" "category" "email" etc.
		// data:  the data to search, this should be the json doc.
		
		public function findField(field:String, data:String):String{
			var exp1:RegExp = new RegExp(formRegExp(field));
			var matchResults1:Array = data.match(exp1);
			if(matchResults1 != null){
				var exp2:RegExp = /: "[^"]*"/;
				var matchResults2:Array = data.match(exp2);
				if(matchResults2 != null){
					var theString:String = matchResults2[0];
					return theString.substr(3,theString.length-4);
				}
			}
			return "oops!";
		}
		
		public function Result()
		{
		}
	}
}